package demo01;

import java.util.Scanner;

/*题目：输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数。
程序分析：利用while语句,条件为输入的字符不为'\n'.*/
public class topic07 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入一行字符:");
        String a = input.nextLine();
        char[]b = a.toCharArray();
        int letters = 0;
        int blank = 0;
        int num = 0;
        int other = 0;
        int i = 0;
        while (i<b.length){
            if(Character.isLetter(b[i])){
                letters++;
            }else if(Character.isSpaceChar(b[i])){
                blank++;
            }else if(Character.isDigit(b[i])){
                num++;
            }else {
                other++;
            }
            i++;
        }
        System.out.println("英文字符共有：" + letters + "个。");
        System.out.println("空格字符共有：" + blank + "个。");
        System.out.println("数字字符共有：" + num + "个。");
        System.out.println("其它字符共有：" + other + "个。");
    }
}
